package cn.maihe.elg.operation.utils;

import cn.maihe.elg.operation.config.GuoGuClientInfoConfig;
import cn.maihe.elg.operation.model.GuoGuClientInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Objects;

/**
 * 自动匹配模板工具类
 * @author SSX
 * @Date 2025/07/08
 */
@Component
public class GuoGuClientInfoUtil {
    private static GuoGuClientInfoUtil guoGuClientInfoUtil;

    @Resource
    private GuoGuClientInfoConfig guoGuClientInfoConfig;

    @PostConstruct
    public void init() {
        guoGuClientInfoUtil = this;
        guoGuClientInfoUtil.guoGuClientInfoConfig = this.guoGuClientInfoConfig;
    }

    public static GuoGuClientInfo getClientInfoByClientId(String clientId){
        if(StringUtils.isBlank(clientId)){
            return new GuoGuClientInfo();
        }

        return guoGuClientInfoUtil.guoGuClientInfoConfig.getGuoGuClientInfo().get(clientId);
    }

    public static String getRegionIdByClientId(String clientId){
        if(StringUtils.isBlank(clientId)){
            return StringUtil.EMPTY;
        }

        GuoGuClientInfo guoGuClientInfo = guoGuClientInfoUtil.guoGuClientInfoConfig.getGuoGuClientInfo().get(clientId);
        if(Objects.isNull(guoGuClientInfo)){
            return StringUtil.EMPTY;
        }

        return guoGuClientInfo.getRegionId();
    }
}
